<template>
  <div>
    <!-- 面包屑导航区域 -->
    <el-breadcrumb>
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图区 -->
    <el-card>
      <el-row>
        <el-col :span="8">
          <el-input placeholder="请输入内容" v-model="queryEntry">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 表格展示区域 -->
      <el-table :data="orderList" style="width: 100%" stripe border class=" mt-20">
        <el-table-column type="index" label="#" width="80"> </el-table-column>
        <el-table-column prop="order_number" label="订单编号"> </el-table-column>
        <el-table-column prop="order_price" label="订单价格"> </el-table-column>
        <el-table-column prop="pay_status" label="是否付款">
          <template slot-scope="scope">
            <el-tag :type="scope.row.pay_status=== '0' ? 'danger' : 'success'">{{scope.row.pay_status === '0' ? '未付款' :'已付款'}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"> </el-table-column>
        <el-table-column prop="create_time" label="下单时间">
          <template slot-scope="scope">
            <span>{{scope.row.create_time | dateFormat}}</span>
          </template>
        </el-table-column>
        <el-table-column lable="操作">
          <template>
            <!-- {{scope.row slot-scope="scope"}} -->
            <el-button type="primary" icon="el-icon-edit" size="mini" @click="showBox"></el-button>
            <el-button type="success" icon="el-icon-location-outline" size="mini" @click="showProgressBox"></el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页区域 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="queryInfo.pagenum"
                     :page-sizes="[1,2,5,10,20]" :page-size="queryInfo.pagesize" layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>

      <!-- 修改地址对话框 -->
      <el-dialog title="修改地址" :visible.sync="boxDialogVisible" width="50%" @close="resetDialog('serAddressFormRef')">

        <el-form ref="serAddressFormRes" :model="serAddressForm" label-width="80px" :rules="serAddressFoRmule">
          <el-form-item label="省市区/县" prop="addres1" label-width="100px">
            <el-cascader v-model="serAddressForm.addres1" :options="citydate" @change="handleChange"></el-cascader>
          </el-form-item>
          <el-form-item label="详细地址" prop="addres2" label-width="100px">
            <el-input v-model="serAddressForm.addres2"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer">
          <el-button @click="dialogVisible = false" size="mini">取 消</el-button>
          <el-button type="primary" @click="saveAddressForm" size="mini">确 定</el-button>
        </span>
      </el-dialog>
      <!-- 物流进度展示对话框 -->

      <el-dialog title="物流进度" :visible.sync="lookProgressDialogVisible" width="50%">
        <el-timeline :reverse="true">
          <el-timeline-item v-for="(activity, index) in progressInfo" :key="index" :timestamp="activity.time">
            <el-card>
              <h4>{{activity.location}}</h4>
              <p>{{activity.context}}</p>
            </el-card>
          </el-timeline-item>
        </el-timeline>
      </el-dialog>
    </el-card>
  </div>
</template>

<script>
import citydate from './citydata.js'
export default {
  data() {
    return {
      queryInfo: {
        pagenum: 1, // 当前页码    
        query: '', //查询参数       
        pagesize: 10,  // 每页显示条数  
      },
      orderList: [], // 订单列表
      total: 0,// 总条数
      queryEntry: '', // 查询关键词
      boxDialogVisible: false,
      lookProgressDialogVisible: false,
      serAddressForm: {
        addres1: '',
        addres2: ''
      }, // 修改地址对话框表单
      serAddressFoRmule: {
        // 验证规则
        addres1: [
          { required: true, message: '请选择省市区/县', trigger: 'blur' },
        ],
        addres2: [
          { required: true, message: '请输入详细地址', trigger: 'blur' },
        ]
      },
      citydate, // 城市信息
      progressInfo: [], // 物流信息
    }
  },
  created() {
    this.getOrderList()
  },
  computed: {

  },
  components: {

  },
  methods: {
    // 获取订单列表
    async getOrderList() {
      const { data: res } = await this.$http.get('orders', { params: this.queryInfo })
      if (res.meta.status !== 200) {
        return this.$message.error('获取订单列表失败！')
      }
      this.$message.success('获取订单列表成功！')
      this.orderList = res.data.goods
      this.total = res.data.total
      console.log(this.orderList)
    },
    // 设置去第几页
    handleSizeChange(newSize) {
      this.queryInfo.pagesize = newSize
      this.getOrderList()
    },
    // 设置每页几条
    handleCurrentChange(newCurrentPage) {
      this.queryInfo.pagenum = newCurrentPage
      this.getOrderList()
    },
    // 打开修改地址 对话框
    showBox() {
      this.boxDialogVisible = true
    },
    // 获取物流信息
    async showProgressBox() {
      const { data: res } = await this.$http.get('/kuaidi/1106975712662')
      if (res.meta.status !== 200) {
        return this.$message.error('获取订单列表失败！')
      }
      this.progressInfo = res.data
      this.$message.success('获取订单列表成功！')
      console.log(res)
      this.lookProgressDialogVisible = true
    },
    // 级联选择器
    handleChange(e) {
      console.log(e)
    },
    // 关闭对话框
    resetDialog(formName) {
      this.$refs[formName].resetFields();
    },
    // 修改地址对话框 提交
    saveAddressForm() { },
  },

  watch: {

  },

}
</script>

<style scoped lang='less'>
.el-cascader {
  width: 100%;
}
</style>